package com.hantanger.weblog.freemarker;

import freemarker.ext.beans.BeansWrapper;
import freemarker.ext.servlet.FreemarkerServlet;
import freemarker.template.Configuration;
import freemarker.template.TemplateHashModel;
import freemarker.template.TemplateModelException;

public class FreemarkerExtServlet extends FreemarkerServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected Configuration createConfiguration() {
		Configuration cfg = super.createConfiguration();
		TemplateHashModel staticModels = BeansWrapper.getDefaultInstance().getStaticModels();
		try {
			cfg.setSharedVariable("Utils", staticModels.get(Utils.class.getName()));
			cfg.setSharedVariable("compresscn", new CompressCN());
		} catch (TemplateModelException e) {
			e.printStackTrace();
		}
			
		return cfg;
	}
}
